package 跳跃游戏II;

/**
 * @author: AirMan
 * @date: 2025/4/22 14:41
 * @description:
 */
public class Solution {
    public int jump(int[] nums) {
        if (nums.length == 1) {
            return 0;
        }
        int count = 0;
        //当前的覆盖最大区域
        int curDistance = 0;
        //最大的覆盖区域
        int maxDistance = 0;

        for (int i = 0; i < nums.length; i++) {
            maxDistance = Math.max(maxDistance, nums[i] + i);
            if (maxDistance >= nums.length - 1) {
                count++;
                break;
            }
            if (i == curDistance) {
                curDistance = maxDistance;
                count++;
            }
        }
        return count;
    }
}
